<?php
class M_DbTable_Event extends Apps_Db_Table_Abstract {
	protected $_name = 'event';

	const STATUS_ACTIVE  	= 1;
	const STATUS_INACTIVE  	= 0;
	const STATUS_DELETED  	= -1;

	const TYPE_GENERAL    = 1;
	const TYPE_INCENTIVE  = 2;
	const TYPE_MEETING_CONFERENCE = 3;
	const TYPE_EVENT      = 4;

	public function getList() {
		$q = $this->_db
				  ->select()
				  ->from(array('e'   => $this->_name), null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = e.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_EVENT)
				  ->where('e.status =?', self::STATUS_ACTIVE)
				  ->order('e.start_date DESC')
				  ->columns(
				  		array('id'						=>  'e.id',
		                      'type'                    =>  'e.type',
				  		      'is_comming'              =>  'e.is_comming',
							  'description'				=>	'e.description',
							  'title'					=>	'a.en_title'
				  ));
		return $q;
	}

	public function getEvent($id) {
		$q = $this->_db
				  ->select()
				  ->from(array('e'   => $this->_name), null)
				  ->join(array('c'   => 'country'), 'c.id = e.country_id', null)
				  ->join(array('a' 	 => 'article'), 'a.reference_id = e.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_EVENT)
				  ->where('e.id =?', $id)
				  ->columns(
				  		array('id'						=>  'e.id',
							  'description'				=>	'e.description',
				  		      'type'                    =>  'e.type',
				  		      'is_comming'              =>  'e.is_comming',
				  		      'meta_keyword'            =>  'e.meta_keyword',
				  		      'meta_description'        =>  'e.meta_description',
				  		      'header_title'            =>  'e.header_title',

							  'country_id'				=>	'c.id',

							  'thumbnail'    			=>	'a.thumbnail',
							  'title'					=>	'a.title',
							  'en_title'				=>	'a.en_title',
				  			  'overview'				=>	'a.overview',
				  			  'en_overview'				=>	'a.en_overview',
				  			  'detail'					=>	'a.detail',
				  			  'en_detail'				=>	'a.en_detail'
				  ));
		return $q;
	}


	//get list MICE
	public function listMice($type) {
		$q = $this->_db
				  ->select()
				  ->from(array('e'   => $this->_name), null)
				  ->joinLeft(array('c'   => 'country'), 'c.id = e.country_id', null)
				  ->joinLeft(array('a' 	 => 'article'), 'a.reference_id = e.id', null)
				  ->where('a.reference_type =?', M_DbTable_Article::REFERENCE_TYPE_EVENT)
				  ->where('e.status =?', self::STATUS_ACTIVE)
				  ->where('e.type =?', $type)
				  ->columns(
				  		array('id'						=>  'e.id',
							  'description'				=>	'e.description',
				  		      'type'                    =>  'e.type',
				  		      'is_comming'              =>  'e.is_comming',
							  'country_id'				=>	'c.id',
				  		      'thumbnail'    			=>	'a.thumbnail',
				  ));
		
		if($this->getLang() == 'en') {
			$q->columns(array('title'            => 'a.en_title',
							  'overview'         => 'a.en_overview'));
		} else {
			$q->columns(array('title'            => 'a.title',
						 	  'overview'         => 'a.overview'));
		}
		return $q;
	}
}